<?php

namespace app\admin\model\methods;

use think\Model;


class Index extends Model
{

    

    

    // 表名
    protected $name = 'ip_methods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'trueness_con_text',
        'provice_include_text',
        'city_include_text',
        'visit_con_text',
        'carrier_text',
        'begintime_text',
        'endtime_text'
    ];
    

    
    public function getTruenessConList()
    {
        return ['' => __(''), '<' => __('<'), '<=' => __('<='), '=' => __('='), '>=' => __('>='), '>' => __('>')];
    }

    public function getProviceIncludeList()
    {
        return ['' => __(''), '包含' => __('包含'), '不包含' => __('不包含')];
    }

    public function getCityIncludeList()
    {
        return ['' => __(''), '包含' => __('包含'), '不包含' => __('不包含')];
    }

    public function getVisitConList()
    {
        return ['IP访问次数>' => __('Ip访问次数>'), 'IP段访问总次数>' => __('Ip段访问总次数>'), 'IP段访问IP个数>' => __('Ip段访问ip个数>')];
    }

    public function getCarrierList()
    {
        return ['移动' => __('移动'), '联通' => __('联通'), '电信' => __('电信'), '其他' => __('其他')];
    }


    public function getTruenessConTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['trueness_con']) ? $data['trueness_con'] : '');
        $list = $this->getTruenessConList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getProviceIncludeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['provice_include']) ? $data['provice_include'] : '');
        $list = $this->getProviceIncludeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCityIncludeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['city_include']) ? $data['city_include'] : '');
        $list = $this->getCityIncludeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getVisitConTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['visit_con']) ? $data['visit_con'] : '');
        $list = $this->getVisitConList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCarrierTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['carrier']) ? $data['carrier'] : '');
        $list = $this->getCarrierList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getBegintimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['begintime']) ? $data['begintime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getEndtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setBegintimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setEndtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
